<template>
<div id="background">
    <el-container>
        <el-header id="editYearHeadPosition">
                <el-row type="flex" style="height:80%;display:flex;align-items: flex-end">
                       <el-col :xs="2" :sm="2" :md="2" :offset="1" class="imgCol">
                        <img v-bind:src="backIcon" class="backSize" @click="back"/>
                    </el-col>
                    <el-col :xs="6" :sm="6" :md="6" :offset="6" class="imgCol"> 
                        <span class="titleSize">编辑生日</span>
                    </el-col>
                    <el-col :xs="3" :sm="6" :md="6" :offset="5" class="imgCol">
                        <span class="titleSize" @click="editBirthday">保存</span>
                    </el-col>
                </el-row>
        </el-header>
        
        <el-main id="editYearMainPosition">
                <el-row type="flex" class="rowHeight">
                    <el-col class="imgCol">
                           <van-field
                            readonly
                            clickable
                            label="生日"
                            :value="birthday"
                            placeholder="选择生日"
                            @click="show = true"
                        />
                        <van-popup v-model="show" position="bottom">
                            <van-datetime-picker
                                    v-model="dateBirthday"
                                    type="date"
                                    :min-date="minDate"
                                    @confirm="confirm"
                                    @cancel="cancel"
                                />
                        </van-popup>
         
                    
		
                </el-col>
            </el-row>
        </el-main>
    </el-container>
      
</div>    
</template>
<script>
import backIcon from '../../assets/img/mine/geRenZhongXin/back.png'
import { Toast } from 'vant';
export default {
    data(){
        return{
            minDate:'',
            show:false,
            dateBirthday:'',
            birthday:'',
            minDate:'',
            backIcon:backIcon,
            normalHeight:document.documentElement.clientHeight,
        }
    },
    mounted(){
        this.minDate = new Date();
        //确定最小时间为60年前
        var day=60 * 365;
        this.minDate.setDate(this.minDate.getDate() - day);
        console.log("minDate :"+this.minDate);
    //     var bg = document.getElementById("background");
    //    // normalHeight=document.documentElement.clientHeight;
    //     console.log("height:"+normalHeight);
    //     bg.style.height = normalHeight+"px";
    //     bg.style.backgroundColor = "#FFFFFF"
    //     bg.style.margin = "0px";
       var normalHeight=sessionStorage.getItem('normalHeight');

        var head=document.getElementById("editYearHeadPosition");
        var headHeight=normalHeight/30 *4 ;
        console.log("headHeight:"+headHeight);
        head.style.height=headHeight+"px";

        var main=document.getElementById("editYearMainPosition");
        var mainHeight=normalHeight/30 *26;
        console.log("mainHeight:"+mainHeight);
        main.style.height=mainHeight+"px";
        
        var birthday=this.$route.query.birthday;
        if(birthday==null){
            this.birthday='';
            this.dateBirthday='';
        }else{  
            this.birthday=birthday;
            this.dateBirthday=birthday;
        }
        console.log(this.birthday);
    },
    methods:{
        back(){
            console.log("back:");
            this.$router.go(-1);
        },
        //点击确认时的回调
        confirm(val){
            //console.log(val.getFullYear()+'-'+val.getMonth()+1+'-'+val.getDate());
            var year=val.getFullYear();
            var month=val.getMonth()+1;
            var day=val.getDate();
            if(month<10){
                month='0'+month;
            }
            if(day<10){
                day='0'+day;
            }
            console.log(year+'-'+month+'-'+day);
            this.birthday=year+'-'+month+'-'+day;
            this.show=false;
        },
        //点击取消时候的回调
        cancel(){
            console.log("cancel");
            this.show=false;
        },
        //编辑年龄
        editBirthday(){
            var URL=this.IP.IP+'/user/userInfo';
            console.log(URL);
            console.log(this.birthday);
            this.$ajax({
                method:'post',
                url:URL,
                params:{
                    birthday:this.birthday
                },        
            }).then(response=>{
                console.log(response.data);
                var code=response.data.code;
                if(code==0){
                    Toast(response.data.data);
               
                    setTimeout(()=>{
                        this.back();
                    },500)
                }else{
                    Toast(response.data.msg);
                }
            }).catch(error=>{
                console.log(error);
                //Toast(error);
            })
        }
    }
}
</script>
<style>
.van-field__control {
    color: #707070;
}
.van-cell {
    color: #707070;
    font-size: 1em;
}
.van-picker__cancel, .van-picker__confirm {
    color: #53cdf5;
}
.rowHeight{
    height:10%;
    background-color: #ffffff;
    /* margin-top: 10px; */
}
.el-main {
    padding: 0px ;
}
#editYearHeadPosition{
    background-color: #53cdf5;
}

.backSize{
    height: 26px;
}
.titleSize{
    /* font-size:1.125em; */
    color:#ffffff
}
.imgCol{
    display: flex;
    justify-content: center;
    align-items: center;
}
@media screen and (max-height: 600px){
  .backSize{
      height: 22px;
  }
  .titleSize{
      /* font-size: 1em; */
  }
}
</style>
